﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using V5_Model;

namespace V5_DAL
{
    public class DALProductOrder
    {

        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int OrderID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from K_ProductOrder");
            strSql.Append(" where OrderID=@OrderID ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.Int,4)};
            parameters[0].Value = OrderID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ModelProductOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into K_ProductOrder(");
            strSql.Append("MemberID,OrderTime,ShipTime,BuyerName,BuyerPhone,BuyerEmail,BuyerAddress,BuyerPostalcode,ReceiverName,ReceiverPhone,ReceiverEmail,ReceiverProCities,ReceiverAddress,ReceiverPostalcode,Remark,TotalPrice,ProductIDs,ProductPrice,CustomItemPrice,Discount,ShipPrice,AdvancePayment,PaymentType,ShippingType,Score,Weight,Quantity,NeedInvoice,InvoiceHead,InvoiceContent,IsCancelled,IsConfirmed,PayStatus,ShippingStatus,IsFinished,ManageHistory,LastModify,OrderNo,Code,IsAgentF,IsAgentFContent,IsShippingFree)");
            strSql.Append(" values (");
            strSql.Append("@MemberID,@OrderTime,@ShipTime,@BuyerName,@BuyerPhone,@BuyerEmail,@BuyerAddress,@BuyerPostalcode,@ReceiverName,@ReceiverPhone,@ReceiverEmail,@ReceiverProCities,@ReceiverAddress,@ReceiverPostalcode,@Remark,@TotalPrice,@ProductIDs,@ProductPrice,@CustomItemPrice,@Discount,@ShipPrice,@AdvancePayment,@PaymentType,@ShippingType,@Score,@Weight,@Quantity,@NeedInvoice,@InvoiceHead,@InvoiceContent,@IsCancelled,@IsConfirmed,@PayStatus,@ShippingStatus,@IsFinished,@ManageHistory,@LastModify,@OrderNo,@Code,@IsAgentF,@IsAgentFContent,@IsShippingFree)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@MemberID", SqlDbType.Int,4),
					new SqlParameter("@OrderTime", SqlDbType.DateTime),
					new SqlParameter("@ShipTime", SqlDbType.NVarChar,50),
					new SqlParameter("@BuyerName", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerPhone", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerEmail", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerPostalcode", SqlDbType.NVarChar,20),
					new SqlParameter("@ReceiverName", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverPhone", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverEmail", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverProCities", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverPostalcode", SqlDbType.NVarChar,20),
					new SqlParameter("@Remark", SqlDbType.NText),
					new SqlParameter("@TotalPrice", SqlDbType.Money,8),
					new SqlParameter("@ProductIDs", SqlDbType.NVarChar,200),
					new SqlParameter("@ProductPrice", SqlDbType.Money,8),
					new SqlParameter("@CustomItemPrice", SqlDbType.Money,8),
					new SqlParameter("@Discount", SqlDbType.NVarChar,50),
					new SqlParameter("@ShipPrice", SqlDbType.Money,8),
					new SqlParameter("@AdvancePayment", SqlDbType.Money,8),
					new SqlParameter("@PaymentType", SqlDbType.Int,4),
					new SqlParameter("@ShippingType", SqlDbType.Int,4),
					new SqlParameter("@Score", SqlDbType.Int,4),
					new SqlParameter("@Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Quantity", SqlDbType.Int,4),
					new SqlParameter("@NeedInvoice", SqlDbType.TinyInt,1),
					new SqlParameter("@InvoiceHead", SqlDbType.NVarChar,255),
					new SqlParameter("@InvoiceContent", SqlDbType.NVarChar,255),
					new SqlParameter("@IsCancelled", SqlDbType.TinyInt,1),
					new SqlParameter("@IsConfirmed", SqlDbType.TinyInt,1),
					new SqlParameter("@PayStatus", SqlDbType.Int,4),
					new SqlParameter("@ShippingStatus", SqlDbType.Int,4),
					new SqlParameter("@IsFinished", SqlDbType.TinyInt,1),
					new SqlParameter("@ManageHistory", SqlDbType.NText),
					new SqlParameter("@LastModify", SqlDbType.Int,4),
					new SqlParameter("@OrderNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Code", SqlDbType.NVarChar,50),
					new SqlParameter("@IsAgentF", SqlDbType.Int,4),
					new SqlParameter("@IsAgentFContent", SqlDbType.NVarChar,100),
					new SqlParameter("@IsShippingFree", SqlDbType.Int,4)};
            parameters[0].Value = model.MemberID;
            parameters[1].Value = model.OrderTime;
            parameters[2].Value = model.ShipTime;
            parameters[3].Value = model.BuyerName;
            parameters[4].Value = model.BuyerPhone;
            parameters[5].Value = model.BuyerEmail;
            parameters[6].Value = model.BuyerAddress;
            parameters[7].Value = model.BuyerPostalcode;
            parameters[8].Value = model.ReceiverName;
            parameters[9].Value = model.ReceiverPhone;
            parameters[10].Value = model.ReceiverEmail;
            parameters[11].Value = model.ReceiverProCities;
            parameters[12].Value = model.ReceiverAddress;
            parameters[13].Value = model.ReceiverPostalcode;
            parameters[14].Value = model.Remark;
            parameters[15].Value = model.TotalPrice;
            parameters[16].Value = model.ProductIDs;
            parameters[17].Value = model.ProductPrice;
            parameters[18].Value = model.CustomItemPrice;
            parameters[19].Value = model.Discount;
            parameters[20].Value = model.ShipPrice;
            parameters[21].Value = model.AdvancePayment;
            parameters[22].Value = model.PaymentType;
            parameters[23].Value = model.ShippingType;
            parameters[24].Value = model.Score;
            parameters[25].Value = model.Weight;
            parameters[26].Value = model.Quantity;
            parameters[27].Value = model.NeedInvoice;
            parameters[28].Value = model.InvoiceHead;
            parameters[29].Value = model.InvoiceContent;
            parameters[30].Value = model.IsCancelled;
            parameters[31].Value = model.IsConfirmed;
            parameters[32].Value = model.PayStatus;
            parameters[33].Value = model.ShippingStatus;
            parameters[34].Value = model.IsFinished;
            parameters[35].Value = model.ManageHistory;
            parameters[36].Value = model.LastModify;
            parameters[37].Value = model.OrderNo;
            parameters[38].Value = model.Code;
            parameters[39].Value = model.IsAgentF;
            parameters[40].Value = model.IsAgentFContent;
            parameters[41].Value = model.IsShippingFree;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(ModelProductOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update K_ProductOrder set ");
            strSql.Append("MemberID=@MemberID,");
            strSql.Append("OrderTime=@OrderTime,");
            strSql.Append("ShipTime=@ShipTime,");
            strSql.Append("BuyerName=@BuyerName,");
            strSql.Append("BuyerPhone=@BuyerPhone,");
            strSql.Append("BuyerEmail=@BuyerEmail,");
            strSql.Append("BuyerAddress=@BuyerAddress,");
            strSql.Append("BuyerPostalcode=@BuyerPostalcode,");
            strSql.Append("ReceiverName=@ReceiverName,");
            strSql.Append("ReceiverPhone=@ReceiverPhone,");
            strSql.Append("ReceiverEmail=@ReceiverEmail,");
            strSql.Append("ReceiverProCities=@ReceiverProCities,");
            strSql.Append("ReceiverAddress=@ReceiverAddress,");
            strSql.Append("ReceiverPostalcode=@ReceiverPostalcode,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("TotalPrice=@TotalPrice,");
            strSql.Append("ProductIDs=@ProductIDs,");
            strSql.Append("ProductPrice=@ProductPrice,");
            strSql.Append("CustomItemPrice=@CustomItemPrice,");
            strSql.Append("Discount=@Discount,");
            strSql.Append("ShipPrice=@ShipPrice,");
            strSql.Append("AdvancePayment=@AdvancePayment,");
            strSql.Append("PaymentType=@PaymentType,");
            strSql.Append("ShippingType=@ShippingType,");
            strSql.Append("Score=@Score,");
            strSql.Append("Weight=@Weight,");
            strSql.Append("Quantity=@Quantity,");
            strSql.Append("NeedInvoice=@NeedInvoice,");
            strSql.Append("InvoiceHead=@InvoiceHead,");
            strSql.Append("InvoiceContent=@InvoiceContent,");
            strSql.Append("IsCancelled=@IsCancelled,");
            strSql.Append("IsConfirmed=@IsConfirmed,");
            strSql.Append("PayStatus=@PayStatus,");
            strSql.Append("ShippingStatus=@ShippingStatus,");
            strSql.Append("IsFinished=@IsFinished,");
            strSql.Append("ManageHistory=@ManageHistory,");
            strSql.Append("LastModify=@LastModify,");
            strSql.Append("OrderNo=@OrderNo,");
            strSql.Append("Code=@Code,");
            strSql.Append("IsAgentF=@IsAgentF,");
            strSql.Append("IsAgentFContent=@IsAgentFContent,");
            strSql.Append("IsShippingFree=@IsShippingFree");
            strSql.Append(" where OrderID=@OrderID ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.Int,4),
					new SqlParameter("@MemberID", SqlDbType.Int,4),
					new SqlParameter("@OrderTime", SqlDbType.DateTime),
					new SqlParameter("@ShipTime", SqlDbType.NVarChar,50),
					new SqlParameter("@BuyerName", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerPhone", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerEmail", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@BuyerPostalcode", SqlDbType.NVarChar,20),
					new SqlParameter("@ReceiverName", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverPhone", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverEmail", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverProCities", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@ReceiverPostalcode", SqlDbType.NVarChar,20),
					new SqlParameter("@Remark", SqlDbType.NText),
					new SqlParameter("@TotalPrice", SqlDbType.Money,8),
					new SqlParameter("@ProductIDs", SqlDbType.NVarChar,200),
					new SqlParameter("@ProductPrice", SqlDbType.Money,8),
					new SqlParameter("@CustomItemPrice", SqlDbType.Money,8),
					new SqlParameter("@Discount", SqlDbType.NVarChar,50),
					new SqlParameter("@ShipPrice", SqlDbType.Money,8),
					new SqlParameter("@AdvancePayment", SqlDbType.Money,8),
					new SqlParameter("@PaymentType", SqlDbType.Int,4),
					new SqlParameter("@ShippingType", SqlDbType.Int,4),
					new SqlParameter("@Score", SqlDbType.Int,4),
					new SqlParameter("@Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Quantity", SqlDbType.Int,4),
					new SqlParameter("@NeedInvoice", SqlDbType.TinyInt,1),
					new SqlParameter("@InvoiceHead", SqlDbType.NVarChar,255),
					new SqlParameter("@InvoiceContent", SqlDbType.NVarChar,255),
					new SqlParameter("@IsCancelled", SqlDbType.TinyInt,1),
					new SqlParameter("@IsConfirmed", SqlDbType.TinyInt,1),
					new SqlParameter("@PayStatus", SqlDbType.Int,4),
					new SqlParameter("@ShippingStatus", SqlDbType.Int,4),
					new SqlParameter("@IsFinished", SqlDbType.TinyInt,1),
					new SqlParameter("@ManageHistory", SqlDbType.NText),
					new SqlParameter("@LastModify", SqlDbType.Int,4),
					new SqlParameter("@OrderNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Code", SqlDbType.NVarChar,50),
					new SqlParameter("@IsAgentF", SqlDbType.Int,4),
					new SqlParameter("@IsAgentFContent", SqlDbType.NVarChar,100),
					new SqlParameter("@IsShippingFree", SqlDbType.Int,4)};
            parameters[0].Value = model.OrderID;
            parameters[1].Value = model.MemberID;
            parameters[2].Value = model.OrderTime;
            parameters[3].Value = model.ShipTime;
            parameters[4].Value = model.BuyerName;
            parameters[5].Value = model.BuyerPhone;
            parameters[6].Value = model.BuyerEmail;
            parameters[7].Value = model.BuyerAddress;
            parameters[8].Value = model.BuyerPostalcode;
            parameters[9].Value = model.ReceiverName;
            parameters[10].Value = model.ReceiverPhone;
            parameters[11].Value = model.ReceiverEmail;
            parameters[12].Value = model.ReceiverProCities;
            parameters[13].Value = model.ReceiverAddress;
            parameters[14].Value = model.ReceiverPostalcode;
            parameters[15].Value = model.Remark;
            parameters[16].Value = model.TotalPrice;
            parameters[17].Value = model.ProductIDs;
            parameters[18].Value = model.ProductPrice;
            parameters[19].Value = model.CustomItemPrice;
            parameters[20].Value = model.Discount;
            parameters[21].Value = model.ShipPrice;
            parameters[22].Value = model.AdvancePayment;
            parameters[23].Value = model.PaymentType;
            parameters[24].Value = model.ShippingType;
            parameters[25].Value = model.Score;
            parameters[26].Value = model.Weight;
            parameters[27].Value = model.Quantity;
            parameters[28].Value = model.NeedInvoice;
            parameters[29].Value = model.InvoiceHead;
            parameters[30].Value = model.InvoiceContent;
            parameters[31].Value = model.IsCancelled;
            parameters[32].Value = model.IsConfirmed;
            parameters[33].Value = model.PayStatus;
            parameters[34].Value = model.ShippingStatus;
            parameters[35].Value = model.IsFinished;
            parameters[36].Value = model.ManageHistory;
            parameters[37].Value = model.LastModify;
            parameters[38].Value = model.OrderNo;
            parameters[39].Value = model.Code;
            parameters[40].Value = model.IsAgentF;
            parameters[41].Value = model.IsAgentFContent;
            parameters[42].Value = model.IsShippingFree;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int OrderID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from K_ProductOrder ");
            strSql.Append(" where OrderID=@OrderID ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.Int,4)};
            parameters[0].Value = OrderID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelProductOrder GetModel(int OrderID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 OrderID,MemberID,OrderTime,ShipTime,BuyerName,BuyerPhone,BuyerEmail,BuyerAddress,BuyerPostalcode,ReceiverName,ReceiverPhone,ReceiverEmail,ReceiverProCities,ReceiverAddress,ReceiverPostalcode,Remark,TotalPrice,ProductIDs,ProductPrice,CustomItemPrice,Discount,ShipPrice,AdvancePayment,PaymentType,ShippingType,Score,Weight,Quantity,NeedInvoice,InvoiceHead,InvoiceContent,IsCancelled,IsConfirmed,PayStatus,ShippingStatus,IsFinished,ManageHistory,LastModify,OrderNo,Code,IsAgentF,IsAgentFContent,IsShippingFree from K_ProductOrder ");
            strSql.Append(" where OrderID=@OrderID ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.Int,4)};
            parameters[0].Value = OrderID;

            ModelProductOrder model = new ModelProductOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["OrderID"].ToString() != "")
                {
                    model.OrderID = int.Parse(ds.Tables[0].Rows[0]["OrderID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MemberID"].ToString() != "")
                {
                    model.MemberID = int.Parse(ds.Tables[0].Rows[0]["MemberID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderTime"].ToString() != "")
                {
                    model.OrderTime = DateTime.Parse(ds.Tables[0].Rows[0]["OrderTime"].ToString());
                }
                model.ShipTime = ds.Tables[0].Rows[0]["ShipTime"].ToString();
                model.BuyerName = ds.Tables[0].Rows[0]["BuyerName"].ToString();
                model.BuyerPhone = ds.Tables[0].Rows[0]["BuyerPhone"].ToString();
                model.BuyerEmail = ds.Tables[0].Rows[0]["BuyerEmail"].ToString();
                model.BuyerAddress = ds.Tables[0].Rows[0]["BuyerAddress"].ToString();
                model.BuyerPostalcode = ds.Tables[0].Rows[0]["BuyerPostalcode"].ToString();
                model.ReceiverName = ds.Tables[0].Rows[0]["ReceiverName"].ToString();
                model.ReceiverPhone = ds.Tables[0].Rows[0]["ReceiverPhone"].ToString();
                model.ReceiverEmail = ds.Tables[0].Rows[0]["ReceiverEmail"].ToString();
                model.ReceiverProCities = ds.Tables[0].Rows[0]["ReceiverProCities"].ToString();
                model.ReceiverAddress = ds.Tables[0].Rows[0]["ReceiverAddress"].ToString();
                model.ReceiverPostalcode = ds.Tables[0].Rows[0]["ReceiverPostalcode"].ToString();
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["TotalPrice"].ToString() != "")
                {
                    model.TotalPrice = decimal.Parse(ds.Tables[0].Rows[0]["TotalPrice"].ToString());
                }
                model.ProductIDs = ds.Tables[0].Rows[0]["ProductIDs"].ToString();
                if (ds.Tables[0].Rows[0]["ProductPrice"].ToString() != "")
                {
                    model.ProductPrice = decimal.Parse(ds.Tables[0].Rows[0]["ProductPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomItemPrice"].ToString() != "")
                {
                    model.CustomItemPrice = decimal.Parse(ds.Tables[0].Rows[0]["CustomItemPrice"].ToString());
                }
                model.Discount = ds.Tables[0].Rows[0]["Discount"].ToString();
                if (ds.Tables[0].Rows[0]["ShipPrice"].ToString() != "")
                {
                    model.ShipPrice = decimal.Parse(ds.Tables[0].Rows[0]["ShipPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AdvancePayment"].ToString() != "")
                {
                    model.AdvancePayment = decimal.Parse(ds.Tables[0].Rows[0]["AdvancePayment"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentType"].ToString() != "")
                {
                    model.PaymentType = int.Parse(ds.Tables[0].Rows[0]["PaymentType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShippingType"].ToString() != "")
                {
                    model.ShippingType = int.Parse(ds.Tables[0].Rows[0]["ShippingType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Score"].ToString() != "")
                {
                    model.Score = int.Parse(ds.Tables[0].Rows[0]["Score"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Weight"].ToString() != "")
                {
                    model.Weight = decimal.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Quantity"].ToString() != "")
                {
                    model.Quantity = int.Parse(ds.Tables[0].Rows[0]["Quantity"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NeedInvoice"].ToString() != "")
                {
                    model.NeedInvoice = int.Parse(ds.Tables[0].Rows[0]["NeedInvoice"].ToString());
                }
                model.InvoiceHead = ds.Tables[0].Rows[0]["InvoiceHead"].ToString();
                model.InvoiceContent = ds.Tables[0].Rows[0]["InvoiceContent"].ToString();
                if (ds.Tables[0].Rows[0]["IsCancelled"].ToString() != "")
                {
                    model.IsCancelled = int.Parse(ds.Tables[0].Rows[0]["IsCancelled"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsConfirmed"].ToString() != "")
                {
                    model.IsConfirmed = int.Parse(ds.Tables[0].Rows[0]["IsConfirmed"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PayStatus"].ToString() != "")
                {
                    model.PayStatus = int.Parse(ds.Tables[0].Rows[0]["PayStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShippingStatus"].ToString() != "")
                {
                    model.ShippingStatus = int.Parse(ds.Tables[0].Rows[0]["ShippingStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsFinished"].ToString() != "")
                {
                    model.IsFinished = int.Parse(ds.Tables[0].Rows[0]["IsFinished"].ToString());
                }
                model.ManageHistory = ds.Tables[0].Rows[0]["ManageHistory"].ToString();
                if (ds.Tables[0].Rows[0]["LastModify"].ToString() != "")
                {
                    model.LastModify = int.Parse(ds.Tables[0].Rows[0]["LastModify"].ToString());
                }
                model.OrderNo = ds.Tables[0].Rows[0]["OrderNo"].ToString();
                model.Code = ds.Tables[0].Rows[0]["Code"].ToString();
                if (ds.Tables[0].Rows[0]["IsAgentF"].ToString() != "")
                {
                    model.IsAgentF = int.Parse(ds.Tables[0].Rows[0]["IsAgentF"].ToString());
                }
                model.IsAgentFContent = ds.Tables[0].Rows[0]["IsAgentFContent"].ToString();
                if (ds.Tables[0].Rows[0]["IsShippingFree"].ToString() != "")
                {
                    model.IsShippingFree = int.Parse(ds.Tables[0].Rows[0]["IsShippingFree"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select OrderID,MemberID,OrderTime,ShipTime,BuyerName,BuyerPhone,BuyerEmail,BuyerAddress,BuyerPostalcode,ReceiverName,ReceiverPhone,ReceiverEmail,ReceiverProCities,ReceiverAddress,ReceiverPostalcode,Remark,TotalPrice,ProductIDs,ProductPrice,CustomItemPrice,Discount,ShipPrice,AdvancePayment,PaymentType,ShippingType,Score,Weight,Quantity,NeedInvoice,InvoiceHead,InvoiceContent,IsCancelled,IsConfirmed,PayStatus,ShippingStatus,IsFinished,ManageHistory,LastModify,OrderNo,Code,IsAgentF,IsAgentFContent,IsShippingFree ");
            strSql.Append(" FROM K_ProductOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM K_ProductOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "K_ProductOrder";
            parameters[1].Value = "OrderID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 1;
            parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
        }

        #endregion  成员方法
    }
}
